<style lang="scss" scoped>

</style>

<template>
    <div class="topbar">
        <span class="leftbtn" @click="goback"><Icon type="ios-arrow-back"></Icon></span>
        <span class="centertitle">{{title}}</span>
        <span class="rightbtn" @click="edit" v-show="topBarParam.btnEdit">编辑</span>    
        <span class="rightbtn" @click="firstSave" v-show="!topBarParam.btnEdit&&topBarParam.btnToggle&&topBarParam.firstSaveShow">保存</span>                 
        <span class="rightbtn" @click="nextStep" v-show="!topBarParam.btnEdit&&topBarParam.btnToggle">下一页</span>
        <span class="rightbtn" @click="save" v-show="!topBarParam.btnEdit&&!topBarParam.btnToggle">保存</span>
        <span class="rightbtn" @click="saveTemp" v-show="!topBarParam.btnEdit&&topBarParam.btnTemp">暂存</span>        
    </div>
</template>

<script>
import { sampleData } from "api/index.js";
export default {
  name: "topbar",
  data() {
    return {
      title: "",
      topBarParam: {
        btnToggle: true, //控制下一步的内容是否出现
        btnEdit: false, //控制编辑按钮是否出现
        firstSaveShow:false, //跟下一步在一起的保存按钮是否显示
        btnTemp:true  //暂存按钮是否显示，在修改样本情况下不显示
      }
    };
  },
  methods: {
    goback() {
      if (this.topBarParam.btnToggle == false) {
        this.topBarParam.btnToggle = true;
        this.$emit("partToggle", this.topBarParam);
      } else {
        this.$router.go(-1);
      }
    },
    edit() {
      this.topBarParam.btnEdit = false;
      this.$emit("toggleEditStatus");
    },
    showPartTwo() { //父组件调用子组件的事件
      this.topBarParam.btnToggle = false;
      this.$emit("partToggle", this.topBarParam);
    },    
    nextStep() {
      this.$emit("clickNextStep", this.topBarParam);
    },
    firstSave(){
      this.$emit("saveItem", this.topBarParam);
    },
    save() {
      this.$emit("saveItem", this.topBarParam);
    },
    saveTemp(){
      this.$emit("saveTemp")
    }
  },
  mounted() {
    if (this.$store.state.operation == "edit") {
      this.title = "我的样本";
      this.topBarParam.btnEdit = true;
      this.topBarParam.firstSaveShow=true;
      this.topBarParam.btnTemp=this.$store.state.btnTemp;
    } else {
      this.title = "新建样本";
      this.topBarParam.btnEdit = false;      
    }
    
  }
};
</script>



